<?php


namespace app\admin\business;


use app\common\model\ConsignorItem;
use app\common\model\ConsignorItemAddMember;

class freightBus
{
    public $consignorItemModel = null;
    public $consignorItemAddMemberModel=null;
    public function __construct()
    {
        $this->consignorItemModel = new ConsignorItem();
        $this->consignorItemAddMemberModel = new ConsignorItemAddMember();
    }
    public function getAllListPage($title,$start_time,$end_time,$paging,$where){

        if($end_time!=''&&$start_time!=''){
            $res = $this->consignorItemModel->getListByTime($title,$start_time,$end_time,$paging,$where);
        }else{
            $res = $this->consignorItemModel->getListByTitle($title,$paging,$where);
        }
//        if(empty($where)){
//            $res = $this->consignorItemModel->getAllListByPage($paging);
//        }else{
//            $res = $this->consignorItemModel->getListByPage($where,$paging);
//        }

        return $res;
    }
    public function getItemByIdBus($id){

        $result = $this->consignorItemModel->getItemById($id);
        if(empty($result)){
            throw new \think\Exception("获取失败，请检查数据库连接");
        }
        return $result;
    }
    public function changeStatusBus($where,$data){

        $result = $this->consignorItemModel->updateItem($where,$data);
        if(empty($result)){
            throw new \think\Exception('状态未更改，无法变更');
        }
        return $result;
    }
    public function removeFreightBus($id){
        $result = $this->consignorItemModel->removeItem($id);
        if(empty($result)){
            throw new \think\Exception('删除失败或者删除目标不存在');
        }
        $this->consignorItemAddMemberModel->removeItem($id);
        return $result;
    }
    public function getApplyMemberListBus($where,$paging){
        $result = $this->consignorItemAddMemberModel->getListByPage($where,$paging);
        return $result;
    }

}